-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(imports): support for import attributes in Vite #17485
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Hi! lint job fails since |
That's weird, the ESLint config is already using the TypeScript parser, which does support import attributes. https://github.com/redfox-mx/vite/blob/1f2d0f60cf008fb0dbba7bbf34c1b1d96cbfd7db/eslint.config.js#L36 See: https://x.com/bradzacher/status/1772901399518408775 I just used it myself, without any config: https://github.com/refined-github/shorten-repo-url/pull/48/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R34 |
I know! But i dont really know how fix it. I get this message if I remove it form D:\repos\vite\playground\resolve\import-attributes.js
1:74 error Parsing error: ';' expected BTW, no matter if I add or not ';', it doesn't desappear. Maybe it is caused by pnpm resolution to typescript 5.2.2 and import attributes are added in 5.3 Lines 133 to 135 in 61357f6
|
@fregante yep! Typescript supports import attributes in v5.3 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html |
I just realized:
That's not what I'd want though, if the import attributes are removed they will be broken. I'm using Vite to bundle a library that imports a third-party JSON file. Here I'm using Vite for tree-shaking, without bundling external dependencies. |
Well, import attribute removal is not about vite (only), rollup output removes attributes no matter what you do https://stackblitz.com/edit/rollup-import-attributes?file=rollup.config.js In that sense, I updated the NOTE: Remember, vite uses esbuild for development, but at build time, rollup bundles our code. If you want a transpiler option you can opt by esbuild, whin bundle option https://esbuild.github.io/getting-started/#bundling-for-the-browser |
Thanks @redfox-mx! That mostly worked for me |
Hi @sheremet-va, nice to meet you. I update this pr to support import atributes into vite system, now covers hooks (not only virtual modules) and module graph integration. I tried to write a test to cover import attributes proposal and read more about how @bluwy propose changes in #12140, so now import attributes metadata is preserved into module node. Have a nice day n.n |
Maybe I don't really know if it is part of the plans for the vite team. So, I close this PR. Maybe in the future when environment API or vite 6 will be ready. Idk |
I am actually invested in supporting this, I've bumped the priority a bit higher to discuss this in the next team meeting |
Description
Fixes #14674, #12140
Adds support for import attributes by parsing them in the import analysis plugin.
Additional context
How this works:
Build phase
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
PS: this pr solve some errors of #15654